package Easy合并链表;

import org.testng.annotations.Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Solution1 {
    public ListNode mergeTwoLists(ListNode l1, ListNode l2){

        ListNode head=new ListNode(),tail=new ListNode();
        List<Integer> list = new ArrayList();
        if (l1 == null)
            return l2;
        if (l2 == null)
            return l1;
        while(l1 != null){
            list.add(l1.val);
            l1 = l1.next;
        }
        while(l2 != null){
            list.add(l2.val);
            l2 = l2.next;
        }

        Collections.sort(list);
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
            if(i == 0) {
                tail.val = list.get(i);
                head = tail;
            }
            else {
                tail.next = new ListNode(list.get(i), null);
                tail = tail.next;
            }
        }

        return head;
    }

    @Test
    public void test(){
//        ListNode l1 = new ListNode(1,new ListNode(2,new ListNode(4,null)));
//        ListNode l2 = new ListNode(1,new ListNode(3,new ListNode(4,null)));
        ListNode l1=null;
        ListNode l2=null;
        ListNode T1 = mergeTwoLists(l1,l2);

        while(T1 != null){
            System.out.println(T1.val);
            T1 = T1.next;
        }
    }
}
